package cn.ljy.mes.web.controller.backstage.shop;


import cn.ljy.authority.model.param.ProductTransferForm;
import cn.ljy.authority.web.controller.backstage.BaseBackstageController;
import cn.ljy.common.model.result.ResponseData;
import cn.ljy.mes.model.ShopProduct;
import cn.ljy.mes.model.query.ShopProductQuery;
import cn.ljy.mes.service.ShopProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

@Api(tags = "后台商城汽车模块")
@RestController
@RequestMapping(value = "/backstage/shop/product")
public class ShopProductController extends BaseBackstageController<ShopProduct, ShopProductQuery,String> {

    @Autowired
    private ShopProductService baseService;

    @Override
    protected String getAuthorityPrefix() {
        return "shop:product"; // 定义模块权限前缀
    }

    @PreAuthorize("hasAuthority('shop:product:edit')")
    @ApiOperation(value = "将产品批量转移到指定栏目下", notes = "将产品批量转移到指定栏目下")
    @ApiImplicitParam(name = "productTransferForm", value = "封装的用于接收productIds[]和productTypeId的表单对象", paramType = "body", dataType="ProductTransferForm",required = true)
    @PatchMapping("/transfer")
    public ResponseData transferProductTypeBySelect(@RequestBody @NotNull ProductTransferForm productTransferForm){
        baseService.updateProductToTransferProductTypeBySelect(productTransferForm.getProductIds(),productTransferForm.getProductTypeId());
        return ResponseData.success("转移成功",null);
    }
}
